package com.hmsproject.search.managedbean;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import org.primefaces.event.map.OverlaySelectEvent;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;

import com.hmsproject.datastructures.event.Event;
import com.hmsproject.db.inmemorydb.EventListProducer;
import com.hmsproject.search.bean.HotelInfo;

@ManagedBean
@ViewScoped
public class MapView {

	private MapModel mapModel = new DefaultMapModel();

	@ManagedProperty(value = "#{searchView}")
	private SearchView searchView;

	@ManagedProperty(value = "#{eventListProducer}")
	EventListProducer eventListProducer;

	private Marker marker;

	public MapModel getMapModel() {

		
		List<Event> events = eventListProducer.getEventList(searchView
				.getSearchBean().getPlaceBean().getPlaceName());

		
		for (Event event : events) {
			if (event.getLongtitude() != null) {         
				mapModel.addOverlay(new Marker(new LatLng(event.getLalititude(),event.getLongtitude()),event.getEventName(),event.getImageName(),event.getImageName()));
			}
		}

		for (HotelInfo hotelInfo : searchView
				.getHotels()) {
			Marker marker = new Marker(new LatLng(hotelInfo
					.getHotel().getLalititude(), hotelInfo
					.getHotel().getLongtitude()), hotelInfo
					.getHotel().getName(),hotelInfo.getHotel().getHotelImage().getFilePath());
			mapModel.addOverlay(marker);
			
		}

		return mapModel;
	}

	public void setMapModel(MapModel emptyModel) {
		this.mapModel = emptyModel;
	}

	public SearchView getSearchView() {
		return searchView;
	}

	public void setSearchView(SearchView searchView) {
		this.searchView = searchView;
	}

	public EventListProducer getEventListProducer() {
		return eventListProducer;
	}

	public void setEventListProducer(EventListProducer eventListProducer) {
		this.eventListProducer = eventListProducer;
	}

	public Marker getMarker() {
		return marker;
	}

	public void onMarkerSelect(OverlaySelectEvent event) {
		marker = (Marker) event.getOverlay();
	}

}
